package com.edgarli.web.controller.gamble;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.edgarli.common.annotation.Log;
import com.edgarli.common.core.controller.BaseController;
import com.edgarli.common.core.domain.AjaxResult;
import com.edgarli.common.enums.BusinessType;
import com.edgarli.gamble.domain.TLotto;
import com.edgarli.gamble.service.ITLottoService;
import com.edgarli.common.utils.poi.ExcelUtil;
import com.edgarli.common.core.page.TableDataInfo;

/**
 * 大乐透Controller
 *
 * @author EdgarLi
 * @date 2024-08-14
 */
@RestController
@RequestMapping("/gamble/lotto")
public class TLottoController extends BaseController
{
    @Autowired
    private ITLottoService tLottoService;

    /**
     * 查询大乐透列表
     */
    @PreAuthorize("@ss.hasPermi('gamble:lotto:list')")
    @GetMapping("/list")
    public TableDataInfo list(TLotto tLotto)
    {
        startPage();
        List<TLotto> list = tLottoService.selectTLottoList(tLotto);
        return getDataTable(list);
    }
    /**
     * 预估大乐透列表
     */
    @GetMapping("/estimate")
    public void estimate()
    {
        tLottoService.estimate();
    }

    /**
     * 导出大乐透列表
     */
    @PreAuthorize("@ss.hasPermi('gamble:lotto:export')")
    @Log(title = "大乐透", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TLotto tLotto)
    {
        List<TLotto> list = tLottoService.selectTLottoList(tLotto);
        ExcelUtil<TLotto> util = new ExcelUtil<TLotto>(TLotto.class);
        util.exportExcel(response, list, "大乐透数据");
    }

    /**
     * 获取大乐透详细信息
     */
    @PreAuthorize("@ss.hasPermi('gamble:lotto:query')")
    @GetMapping(value = "/{lottoId}")
    public AjaxResult getInfo(@PathVariable("lottoId") Long lottoId)
    {
        return AjaxResult.success(tLottoService.selectTLottoByLottoId(lottoId));
    }

    /**
     * 新增大乐透
     */
    @PreAuthorize("@ss.hasPermi('gamble:lotto:add')")
    @Log(title = "大乐透", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLotto tLotto)
    {
        return toAjax(tLottoService.saveOrUpdate(tLotto));
    }

    /**
     * 修改大乐透
     */
    @PreAuthorize("@ss.hasPermi('gamble:lotto:edit')")
    @Log(title = "大乐透", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLotto tLotto)
    {
        return toAjax(tLottoService.saveOrUpdate(tLotto));
    }

    /**
     * 删除大乐透
     */
    @PreAuthorize("@ss.hasPermi('gamble:lotto:remove')")
    @Log(title = "大乐透", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lottoIds}")
    public AjaxResult remove(@PathVariable Long[] lottoIds)
    {
        return toAjax(tLottoService.deleteTLottoByLottoIds(lottoIds));
    }
}
